<template>
  <div class="notification-settings">
    <!-- 头部栏 -->
    <HeaderComponent 
      :isLoggedIn="isLoggedIn"
      :userInfo="userInfo"
      :showUserPanel="showUserPanel"
      @open-login="$emit('open-login')"
      @toggle-user-panel="$emit('toggle-user-panel')"
      @logout="$emit('logout')"
    />
    
    <!-- 主布局 -->
    <div class="main-layout">
      <!-- 左侧设置导航栏 -->
      <aside class="settings-sidebar">
        <div class="sidebar-header">
          <h3>设置</h3>
        </div>
        <ul class="settings-nav">
          <li class="nav-item">
            <router-link to="/user/settings/profile" class="nav-link">
              <span class="nav-icon">👤</span>
              <span>个人资料</span>
            </router-link>
          </li>
          <li class="nav-item">
            <router-link to="/user/settings/account" class="nav-link">
              <span class="nav-icon">🔐</span>
              <span>账号设置</span>
            </router-link>
          </li>
          <li class="nav-item">
            <router-link to="/user/settings/general" class="nav-link">
              <span class="nav-icon">⚙️</span>
              <span>通用设置</span>
            </router-link>
          </li>
          <li class="nav-item active">
            <router-link to="/user/settings/notifications" class="nav-link">
              <span class="nav-icon">🔔</span>
              <span>消息设置</span>
            </router-link>
          </li>
          <li class="nav-item">
            <router-link to="/user/settings/block" class="nav-link">
              <span class="nav-icon">🚫</span>
              <span>屏蔽管理</span>
            </router-link>
          </li>
          <li class="nav-item">
            <router-link to="/user/settings/tags" class="nav-link">
              <span class="nav-icon">🏷️</span>
              <span>标签管理</span>
            </router-link>
          </li>
        </ul>
      </aside>
      
      <!-- 右侧内容区 -->
      <main class="settings-content">
        <div class="settings-header">
          <h2>消息设置</h2>
          <p>管理您的通知偏好和消息推送</p>
        </div>
        
        <div class="form-section">
          <h3>推送通知</h3>
          <div class="form-group">
            <label class="switch-item">
              <span class="switch-label">启用推送通知</span>
              <div class="switch">
                <input type="checkbox" v-model="notifications.pushEnabled" />
                <span class="slider"></span>
              </div>
            </label>
          </div>
          
          <div class="form-group">
            <label class="switch-item">
              <span class="switch-label">新文章推送</span>
              <div class="switch">
                <input type="checkbox" v-model="notifications.newArticles" :disabled="!notifications.pushEnabled" />
                <span class="slider"></span>
              </div>
            </label>
          </div>
          
          <div class="form-group">
            <label class="switch-item">
              <span class="switch-label">评论回复推送</span>
              <div class="switch">
                <input type="checkbox" v-model="notifications.comments" :disabled="!notifications.pushEnabled" />
                <span class="slider"></span>
              </div>
            </label>
          </div>
          
          <div class="form-group">
            <label class="switch-item">
              <span class="switch-label">点赞推送</span>
              <div class="switch">
                <input type="checkbox" v-model="notifications.likes" :disabled="!notifications.pushEnabled" />
                <span class="slider"></span>
              </div>
            </label>
          </div>
        </div>
        
        <div class="form-section">
          <h3>邮件通知</h3>
          <div class="form-group">
            <label class="switch-item">
              <span class="switch-label">启用邮件通知</span>
              <div class="switch">
                <input type="checkbox" v-model="notifications.emailEnabled" />
                <span class="slider"></span>
              </div>
            </label>
          </div>
          
          <div class="form-group">
            <label class="switch-item">
              <span class="switch-label">每日摘要邮件</span>
              <div class="switch">
                <input type="checkbox" v-model="notifications.dailyDigest" :disabled="!notifications.emailEnabled" />
                <span class="slider"></span>
              </div>
            </label>
          </div>
          
          <div class="form-group">
            <label class="switch-item">
              <span class="switch-label">活动邮件</span>
              <div class="switch">
                <input type="checkbox" v-model="notifications.activities" :disabled="!notifications.emailEnabled" />
                <span class="slider"></span>
              </div>
            </label>
          </div>
        </div>
        
        <div class="form-section">
          <h3>免打扰时间</h3>
          <div class="form-group">
            <label class="switch-item">
              <span class="switch-label">启用免打扰模式</span>
              <div class="switch">
                <input type="checkbox" v-model="notifications.doNotDisturb" />
                <span class="slider"></span>
              </div>
            </label>
          </div>
          
          <div class="time-range" v-if="notifications.doNotDisturb">
            <div class="form-group">
              <label>开始时间</label>
              <input type="time" v-model="notifications.startTime" />
            </div>
            <div class="form-group">
              <label>结束时间</label>
              <input type="time" v-model="notifications.endTime" />
            </div>
          </div>
        </div>
        
        <div class="form-section">
          <h3>通知频率</h3>
          <div class="form-group">
            <label>推送频率</label>
            <select v-model="notifications.frequency">
              <option value="instant">即时推送</option>
              <option value="hourly">每小时汇总</option>
              <option value="daily">每日汇总</option>
              <option value="weekly">每周汇总</option>
            </select>
          </div>
        </div>
        
        <div class="form-actions">
          <button class="btn-primary" @click="saveNotifications">保存设置</button>
          <button class="btn-secondary" @click="resetNotifications">恢复默认</button>
        </div>
      </main>
    </div>
  </div>
</template>

<script>
import HeaderComponent from '@/components/HeaderComponent.vue';

export default {
  components: {
    HeaderComponent
  },
  name: 'NotificationSettings',
  props: {
    isLoggedIn: {
      type: Boolean,
      default: false
    },
    userInfo: {
      type: Object,
      default: () => ({})
    },
    showUserPanel: {
      type: Boolean,
      default: false
    }
  },
  data() {
    return {
      notifications: {
        pushEnabled: true,
        newArticles: true,
        comments: true,
        likes: false,
        emailEnabled: true,
        dailyDigest: true,
        activities: false,
        doNotDisturb: false,
        startTime: '22:00',
        endTime: '08:00',
        frequency: 'instant'
      },
      originalNotifications: {}
    }
  },
  mounted() {
    this.loadNotifications();
  },
  methods: {
    loadNotifications() {
      // 模拟加载通知设置
      this.originalNotifications = { ...this.notifications };
    },
    saveNotifications() {
      // 保存通知设置
      console.log('保存通知设置:', this.notifications);
      this.$message?.success('通知设置保存成功');
      this.originalNotifications = { ...this.notifications };
    },
    resetNotifications() {
      // 重置通知设置
      this.notifications = {
        pushEnabled: true,
        newArticles: true,
        comments: true,
        likes: false,
        emailEnabled: true,
        dailyDigest: true,
        activities: false,
        doNotDisturb: false,
        startTime: '22:00',
        endTime: '08:00',
        frequency: 'instant'
      };
    }
  }
}
</script>

<style scoped>
.notification-settings {
  min-height: 100vh;
  background-color: #f5f5f5;
}

.main-layout {
  display: flex;
  max-width: 1200px;
  margin: 0 auto;
  background-color: white;
  min-height: calc(100vh - 60px);
}

.settings-sidebar {
  width: 250px;
  background-color: #fff;
  border-right: 1px solid #e5e5e5;
  padding: 20px 0;
}

.sidebar-header {
  padding: 0 20px 20px;
  border-bottom: 1px solid #e5e5e5;
}

.sidebar-header h3 {
  margin: 0;
  font-size: 18px;
  color: #333;
}

.settings-nav {
  list-style: none;
  padding: 0;
  margin: 0;
}

.nav-item {
  margin: 0;
}

.nav-link {
  display: flex;
  align-items: center;
  padding: 12px 20px;
  text-decoration: none;
  color: #666;
  transition: all 0.3s;
}

.nav-link:hover {
  background-color: #f8f9fa;
  color: #007bff;
}

.nav-item.active .nav-link {
  background-color: #e3f2fd;
  color: #007bff;
  border-right: 3px solid #007bff;
}

.nav-icon {
  margin-right: 10px;
  font-size: 16px;
}

.settings-content {
  flex: 1;
  padding: 20px;
  max-width: 800px;
}

.settings-header {
  margin-bottom: 30px;
}

.settings-header h2 {
  margin: 0 0 8px 0;
  font-size: 24px;
  color: #333;
}

.settings-header p {
  margin: 0;
  color: #666;
  font-size: 14px;
}

.form-section {
  background: white;
  border: 1px solid #e5e5e5;
  border-radius: 8px;
  padding: 20px;
  margin-bottom: 20px;
}

.form-section h3 {
  margin: 0 0 20px 0;
  font-size: 18px;
  color: #333;
  border-bottom: 1px solid #e5e5e5;
  padding-bottom: 10px;
}

.form-group {
  margin-bottom: 20px;
}

.form-group label {
  display: block;
  margin-bottom: 8px;
  font-weight: 500;
  color: #333;
}

.form-group select,
.form-group input[type="time"] {
  width: 100%;
  padding: 10px;
  border: 1px solid #ddd;
  border-radius: 4px;
  font-size: 14px;
}

.switch-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  cursor: pointer;
  font-weight: normal;
}

.switch-label {
  flex: 1;
}

.switch {
  position: relative;
  width: 50px;
  height: 24px;
}

.switch input {
  opacity: 0;
  width: 0;
  height: 0;
}

.slider {
  position: absolute;
  cursor: pointer;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background-color: #ccc;
  transition: .4s;
  border-radius: 24px;
}

.slider:before {
  position: absolute;
  content: "";
  height: 18px;
  width: 18px;
  left: 3px;
  bottom: 3px;
  background-color: white;
  transition: .4s;
  border-radius: 50%;
}

input:checked + .slider {
  background-color: #007bff;
}

input:checked + .slider:before {
  transform: translateX(26px);
}

input:disabled + .slider {
  background-color: #e9ecef;
  cursor: not-allowed;
}

.time-range {
  display: flex;
  gap: 20px;
  margin-top: 15px;
}

.time-range .form-group {
  flex: 1;
}

.form-actions {
  display: flex;
  gap: 12px;
  padding-top: 20px;
  border-top: 1px solid #e5e5e5;
}

.btn-primary,
.btn-secondary {
  padding: 10px 20px;
  border: none;
  border-radius: 4px;
  font-size: 14px;
  cursor: pointer;
  transition: background-color 0.3s;
}

.btn-primary {
  background-color: #007bff;
  color: white;
}

.btn-primary:hover {
  background-color: #0056b3;
}

.btn-secondary {
  background-color: #6c757d;
  color: white;
}

.btn-secondary:hover {
  background-color: #545b62;
}
</style>